package com.neuedu.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Util {

    public static void main(String[] args) {
        String password="123456";
        password= Md5Util.md5("40CF619E175325CC4033D0402A671ABAjava01");
        //
        System.out.println(password.toUpperCase());
        //6A8BA3F40C68CF0C021D3E950D4EC2DC
        //98F1E5FFCDF488645D1074DB42969AC7

        //E10ADC3949BA59ABBE56E057F20F883E
        //E10ADC3949BA59ABBE56E057F20F883E


        //40CF619E175325CC4033D0402A671ABA
    }

    public static String md5(String inStr) {

        String hexString = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] digest = md.digest(inStr.getBytes());

            hexString = bytesToHex(digest);


        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return hexString.toUpperCase();
    }

    public static String bytesToHex(byte[] bytes) {
        StringBuilder hexString = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            String hex = Integer.toHexString(0xff & bytes[i]);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
        }
        return hexString.toString();

    }
}
